#region license
/*
 * Copyright (C) 2007 CchenSoft.com
 * 
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License 2.1 or later, as
 * published by the Free Software Foundation. See the included License.txt
 * or http://www.gnu.org/copyleft/lesser.html for details.
 * 
 * Author: Billy Zhang
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using CchenSoft.Portal.Cfg;
using CchenSoft.Portal.Registry;
using CchenSoft.Portal.Model;
using CchenSoft.Portal.Service;
using CchenSoft.Portal.Spi;
using System.Web;

namespace CchenSoft.Portal
{
    public class PortletContext
    {
        private IModule module;
        private User user;

        public PortletContext()
        {
            user = ServiceLocator.UserService.LoggedUser;
        }

        public PortletContext(IModule module)
        {
            this.module = module;
            user = ServiceLocator.UserService.LoggedUser;
        }

        public static PortletContext Current
        {
            get { return (PortletContext)HttpContext.Current.Items["portlet_context"]; }
        }

        public IModule Module
        {
            get { return module; }
        }

        public User User
        {
            get { return user; }
        }

        public T GetService<T>()
        {
            if (module != null)
                return (T)module.Services[typeof(T).Name];
            return default(T);
        }
    }
}
